<template>
    <div class="box" >   
        <div class="left">{{name}}</div>
        <div class="right" >
            <div >
                <div class="img">
                    <img src="../../assets/logo.png" alt="">
                </div>
                <span class="span">王小虎</span>
                 <span class="el-icon-caret-bottom span" ></span>
            </div>
             <p @click='Cancellation' :class="change?'change':''">
                 <span class="el-icon-s-tools"></span>
                 <span>注销</span>
             </p>
        </div>
    </div>
</template>
<script>
import api from '../../api/Basicpath/index'
import axios from 'axios'
export default {
    props:['name'],
    data(){
        return{
           change:false,
        }
    },
    methods:{
        StateChange(){
            this.change=!this.change
        },
        Cancellation(){
            var token = localStorage.getItem('sessionId')
            axios.get(`${api}/gamemall/logout`,{
                headers:{
                    token
                }
            }).then((res)=>{
                if(res.data.code){
                    localStorage.removeItem('sessionId')
                    this.$router.push({
                        path:'/'
                    })
                }
            })
        }
    }
   
}
</script>
<style scoped>
.img{
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: coral;
    display: inline-block;
}
.box{
    cursor: pointer;
}
.box .right{
  position: absolute;
  right: 50px;
}
.box .left{
  position: absolute;
  left: 50px;
}
.right:hover .span{
    color: chartreuse;
}
.right:hover>p{
    display: block;
    position: absolute;
}
.right>p:hover{
    background:rgba(100,100,100.5);
}
.box img{
    width: 20px;
    height: 20px;
}
.right p{
    width: 90px;
    line-height: 30px;
    border: 1px solid #ccc;
    display: none;
    position: absolute;
}
/* .change{
    height: 0!important;
    border: none!important;
} */
</style>